<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <span>SUSteam 管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideIsCollapse ? '64px' : '200px'">
        <!-- 侧边栏折叠和展开 -->
        <div class="toggle-button" @click="toggleCollapse">
          |||
        </div>
        <!-- 侧边栏菜单 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
          router
          :collapse="asideIsCollapse"
          :collapse-transition="false"
          :default-active="activePath"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.name" v-for="item in menuList" :key="item.id">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="item.icon"></i>
              <!-- 文本 -->
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id"
                          @click="saveActivePath(subItem.path)">
              <template slot="title">
                <!-- 图标 -->
                <i :class="subItem.icon"></i>
                <!-- 文本 -->
                <span>{{ subItem.name }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      userList: [],
      asideIsCollapse: false,
      menuList: [
        {
          name: '用户管理',
          id: 1,
          icon: 'iconfont icon-users',
          children: [
            {
              path: '/accounts',
              name: '用户列表',
              icon: 'iconfont icon-user',
              id: 11
            }
          ]
        },
        {
          name: '权限管理',
          id: 2,
          icon: 'iconfont icon-3702mima',
          children: [
            {
              path: '/roles',
              name: '角色管理',
              icon: 'iconfont icon-users',
              id: 21
            },
            {
              path: '/authority',
              name: '权限管理',
              icon: 'iconfont icon-lock_fill',
              id: 22
            }
          ]
        },
        {
          name: '游戏管理',
          id: 3,
          icon: 'iconfont icon-3702mima',
          children: [
            {
              path: '/games',
              name: '游戏列表',
              icon: 'iconfont icon-users',
              id: 31
            },
            {
              path: '/gameTypes',
              name: '游戏类别管理',
              icon: 'iconfont icon-lock_fill',
              id: 32
            }
          ]
        },
        {
          name: '文档管理',
          id: 4,
          icon: 'iconfont icon-3702mima',
          children: [
            {
              path: '/guides',
              name: '文档列表',
              icon: 'iconfont icon-lock_fill',
              id: 42
            }
          ]
        }
      ],
      activePath: '/home'
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 折叠侧边栏
    toggleCollapse () {
      this.asideIsCollapse = !this.asideIsCollapse
    },
    saveActivePath (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;

  div {
    display: flex;
    // 纵向居中对齐
    align-items: center;
  }
}

.iconfont {
  margin-right: 15px;
}

.el-aside {
  background-color: #333744;

  .el-menu {
    border-right: none;
  }
}

.toggle-button {
  background-color: #4A5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.el-main {
  background-color: #eaedf1;
}
</style>
